import Vue from 'vue'
import { setStorage, getStorage} from '@/utils/auth'
import  * as stn from '../constants/storeName'

const has = Vue.directive('has', {
  bind: function (el, binding, vnode) {
    if (binding.value) {
      if (!Vue.prototype.$_has(binding.value)) {
        el.style.display = 'none';
        // el.parentNode.removeChild(el);
      }
    }
  }
});

const operate = Vue.directive('operate', {
  bind: function (el, binding, vnode) {
    if (binding.value) {
      if (!Vue.prototype.$_has(binding.value)) {
        el.disabled = true;
        // el.parentNode.removeChild(el);
      }
    }
  }
});

Vue.prototype.$_has = function (value) {
  let isExist = false;
  let btnPermissionsStr = getStorage(stn.MENUS_PERMISSION);
  if (btnPermissionsStr == undefined || btnPermissionsStr == null) {
    return false;
  }
  if (btnPermissionsStr.indexOf(value) > -1) {
    isExist = true;
  }
  return isExist;
};
export {has,operate}
